local HeroChat = class("HeroChat")
local GameUtils = require("utils.GameUtils")
local Vector3 = require("utils.Vector3")
local StoryHelper = require("gameLogic.story.StoryHelper")

function HeroChat:create()
    local object = G_ResourceManager:loadUI(self.__cname)
    local gameObject, luaScript = GameUtils.instantiate(object)
    return luaScript
end

function HeroChat:ctor()
end

function HeroChat:update()
    if not self._cameraTransform then
        return
    end
    local forward = self._cameraTransform.forward
    self.transform.forward = forward
end

function HeroChat:setCallback(callback)
    self._callback = callback
end

function HeroChat:updateUI(model, id, delay, cameraTransform)
    GameUtils.addChildTo(model.transform, self.transform)
    self.transform.localPosition = Vector3.new(0.75, 1.325, 0.344)
    self.transform.localScale = Vector3.new(0.008, 0.008, 0.008)
    GameUtils.destroy(self.gameObject, delay)
    self:setTalk(StoryHelper.getChat(id))
    self._cameraTransform = cameraTransform
    local forward = self._cameraTransform.forward
    self.transform.forward = forward
end

function HeroChat:setTalk(text)
    self._textChat.text = text
end

function HeroChat:onDestroy()
    if self._callback then
        self._callback()
    end
end

return HeroChat
